<template>
    <div class="goodList">
        <div class="goodItem" v-for="item in goodsList" :key="item.id" @click="getDetail(item.id)">
            <img :src="item.img_url"/>
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="new">￥{{item.sell_price}}</span>
                    <span class="old">￥{{item.market_price}}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </div>
        <mt-button type="danger" size="large"  @click="getmore">加载更多</mt-button>
    </div>
</template>
<script>
export default {
    data(){
        //挂载一些私有组件
        return{
            goodsList:[]
        }
    },
    created(){
        this.getGoodsList()
    },
    methods: {
        getGoodsList(){
            this.$http.get("src/json/goodsList.json").then(result =>{
                if(result.body.status === 0){
                    this.goodsList = this.goodsList.concat(result.body.message)
                }
            })
        },
        getmore(){
            this.getGoodsList()
        },
        getDetail(id){
            this.$router.push("/home/goodsinfo/"+id)
        }
    }
}
</script>
<style lang="scss" scoped>
    .goodList{
        display: flex;
        flex-wrap: wrap; //换行布局
        padding: 7px;
        justify-content: space-between;
        .title{
            color: #000;
        }
        .goodItem{
            width: 49%;
            border:1px solid #ccc;
            box-shadow: 0 0 8px #ccc;
            margin: 3px 0;
            display: flex;
            flex-direction: column; //改变主轴方向，默认是横向，改为纵向
            justify-content: space-between;
            min-height: 293px;
            img{
                width: 100%;
            }
            .info{
                background-color: #eee;
                p{
                    margin: 0;
                    padding: 5px;
                }
                .price{
                    .new{
                        color: red;
                        font-size: 16px;
                        font-weight: bold; //字体加粗
                    }
                    .old{
                        text-decoration: line-through;
                        margin-left: 10px;
                        font-size: 12px;
                    }
                }
                .sell{
                    display: flex;
                    justify-content: space-between;
                }
            }
        }

    }
</style>

